﻿using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using System.IO;
using System.Reflection;
//using NUnit.Framework.SyntaxHelpers;
using Langexplr.Abc;


namespace AbcLibrary.Tests
{
    [TestFixture]
    public class ScriptLoadingTests
    {
        [Test]
        public void TestBasicScriptLoading()
        {
            using (BinaryReader reader = new BinaryReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("AbcLibrary.Tests.files.optionalparameters.as3.abc")))
            {
                AbcFile file = AbcFile.ReadFrom(reader);

                Assert.AreEqual(1, file.Scripts.Length);

                AvmScript script = AvmScript.Create(
                                         file.Scripts[0],
                                         file.Methods,
                                         file.MethodBodies,
                                         file.Instances,
                                         file.ConstantPool,new QualifiedName[]{});

                //System.Diagnostics.Debugger.Break();
                Console.WriteLine(script);

            }
        }

        [Test]
        public void TestHelloWorldScriptLoading()
        {
            using (BinaryReader reader = new BinaryReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("AbcLibrary.Tests.files.hello.abc")))
            {
                //System.Diagnostics.Debugger.Break();
                AbcFile file = AbcFile.ReadFrom(reader);

                Assert.AreEqual(1, file.Scripts.Length);
                Assert.AreEqual(0, file.Classes.Length);
                Assert.AreEqual(0, file.Instances.Length);
                Assert.AreEqual(0, file.Metadata.Length);
                
                AvmScript script = AvmScript.Create(
                                         file.Scripts[0],
                                         file.Methods,
                                         file.MethodBodies,
                                         file.Instances,
                                         file.ConstantPool,new QualifiedName[]{});

                Assert.AreEqual(1, file.Methods.Length);

                Assert.IsTrue(script.InitMethod.ReturnType.Tag == QualifiedName.tag_SQualifiedName);
                Assert.AreEqual("*", script.InitMethod.ReturnType.ToString());
                Assert.AreEqual("", script.InitMethod.Name) ;
                

            }
        }
    }
}
